﻿Public Class frmConfigurarAplicacao
    Inherits formPadrao
    Private departamentoBO As New departamentoBO
    Private PPI As Boolean = System.Configuration.ConfigurationManager.AppSettings("PPI")
    
    Private Sub frmConfigurarAplicacao_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Try

            'Me.ControlBox = False
            Me.WindowState = FormWindowState.Maximized
     
        If Not IsNothing(Configuration.ConfigurationManager.AppSettings("gravaBanco")) Then
                generica.gravaBanco = CType(Configuration.ConfigurationManager.AppSettings("gravaBanco"), Boolean)
            End If

            If Not IsNothing(Configuration.ConfigurationManager.AppSettings("PPI")) Then
                ppi = CType(Configuration.ConfigurationManager.AppSettings("PPI"), Boolean)
            End If

            If generica.gravaBanco Then
                rdSim.Checked = True
                rdNao.Checked = False
            Else
                rdSim.Checked = False
                rdNao.Checked = True
            End If

            If ppi Then
                rdPPIsim.Checked = True
                rdPPINao.Checked = False
            Else
                rdPPIsim.Checked = False

                rdPPINao.Checked = True
            End If

            Me.WindowState = FormWindowState.Maximized

        Catch ex As Exception

            generica.gravaErro(ex)

        End Try

    End Sub

    Private Sub btnSalvar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSalvar.Click

        Try
            If rdSim.Checked Then

                generica.UpdateAppSettings("gravaBanco", True)
            Else
                generica.UpdateAppSettings("gravaBanco", False)
            End If

            If rdPPIsim.Checked Then

                generica.UpdateAppSettings("PPI", True)
            Else
                generica.UpdateAppSettings("PPI", False)
            End If


            If MsgBox("Por se tratar de um arquivo de configuração é necessário sair do sistema para que a alteração surta efeito. Deseja sair agora do programa ?", MsgBoxStyle.YesNo) = vbYes Then
                Application.Exit()
            End If
        Catch ex As Exception
            generica.gravaErro(ex)
        End Try
    End Sub
End Class